package com.bxait.toymail.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.bxait.com.utils.PageUtils;
import com.bxait.com.utils.R;
import com.bxait.com.valid.AddGroup;
import com.bxait.com.valid.UpdateGroup;
import com.bxait.com.valid.UpdateStatusGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.bxait.toymail.product.entity.BrandEntity;
import com.bxait.toymail.product.service.BrandService;



/**
 * import org.apache.shiro.authz.annotation.RequiresPermissions;
 * 品牌
 *
 * @author chen
 * @email 2277411582@qq.com
 * @date 2023-03-13 22:26:35
 */
@RestController
@RequestMapping("product/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    /**
     * @param params
     * @==============History===============<br/>
     * @Description // TODO  获取品牌的列表数据
     * @Date 2023/3/14 22:14
     * @Author <a href="qq:2277411582@qq.com">chen</a>
     * @return com.bxait.com.utils.R
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = brandService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{brandId}")
    public R info(@PathVariable("brandId") Long brandId){
		BrandEntity brand = brandService.getById(brandId);

        return R.ok().put("brand", brand);
    }

    /**
     * @param brand
     * @==============History===============<br/>
     * @Description // TODO  新增品牌信息时,开启增加的分组校验
     * @Date 2023/3/14 22:13
     * @Author <a href="qq:2277411582@qq.com">chen</a>
     * @return com.bxait.com.utils.R
     */
    @RequestMapping("/save")
    public R save(@Validated({AddGroup.class}) @RequestBody BrandEntity brand){
		brandService.save(brand);

        return R.ok();
    }

    /**
     * @param brand
     * @==============History===============<br/>
     * @Description // TODO  品牌的修改方法,开启一个更新的分组的校验,品牌的id,品牌的名称,品牌的logo地址,品牌检索的首字母需要是合法的
     *                       当我们修改了品牌表(pms_brand)的时候,需要同步的将品牌分类关联表同步更新(pms_category_brand_relation)
     * @Date 2023/3/14 21:18
     * @Author <a href="qq:2277411582@qq.com">chen</a>
     * @return com.bxait.com.utils.R
     */
    @RequestMapping("/update")
    public R update(@Validated(UpdateGroup.class) @RequestBody BrandEntity brand){
        brandService.updateDetail(brand);
        return R.ok();
    }


    /***
     * @param brand
     * @==============History===============<br/>
     * @Description // TODO  快速修改品牌状态的方法,校验分组为UpdateStatusGroup,品牌显示状态和品牌id是必须携带的
     * @Date 2023/3/14 21:16 
     * @Author <a href="qq:2277411582@qq.com">chen</a>
     * @return com.bxait.com.utils.R
     */ 
    @RequestMapping("/update/status")
    public R updateStatus(@Validated(UpdateStatusGroup.class) @RequestBody BrandEntity brand){
        brandService.updateById(brand);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] brandIds){
		brandService.removeByIds(Arrays.asList(brandIds));

        return R.ok();
    }


    /*
     * @param brandIds
     * @==============History===============<br/>
     * @Description //   获取当前品牌id对应的品牌信息
     * @Date 2023/4/16 2023/4/16
     * @Author < a href="2277411582@qq.com">chen</ a>
     * @return [java.util.List<java.lang.Long>]
     */
    @GetMapping("/infos")
    public R brandInfos(@RequestParam("brandIds") List<Long> brandIds){
        List<BrandEntity> brands = brandService.getBrandByIds(brandIds);
        return R.ok().put("brand", brands);
    }

}
